package com.qf.shop.search.controller;

import com.qf.shop.common.vo.GoodsVo;
import com.qf.shop.search.service.impl.GoodsServiceImpl;
import javafx.beans.property.adapter.ReadOnlyJavaBeanBooleanProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.ArrayStack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/search")
@Slf4j
public class SearchGoodsController {

    @Autowired
    private GoodsServiceImpl goodsService;

    @GetMapping("/searchGoods")
    public String searchGoods(@RequestParam Map<String,Object> param, ModelMap modelMap) throws Exception {
        log.debug("keyword:{}",param);
        List<Map<String,Object>> goodsMapList = goodsService.search(param);
        log.debug("goodsMapList:{}",goodsMapList);
        modelMap.put("goodsMapList", goodsMapList);
        return "searchList";
    }

    public  Map<String, Object> testData(){
        // 准备两个图片
        Map<String, Object> pngMap1 = new HashMap();
        pngMap1.put("gid", 10);
        pngMap1.put("url", "wwww.jd.com");

        Map<String, Object> pngMap2 = new HashMap();
        pngMap2.put("gid", 10);
        pngMap2.put("url", "wwww.tb.com");
        pngMap2.put("core", 1);

        // 2把两个图片放到集合中
        List<Map<String, Object>> goodsPngList = new ArrayList<>();
        goodsPngList.add(pngMap1);
        goodsPngList.add(pngMap2);

        // 3.把图片的集合放到
        Map<String, Object> goodsMap = new HashMap<>();
        goodsMap.put("gname", "华为手机");
        goodsMap.put("gdesc", "华为手机大屏，5G");
        goodsMap.put("stock", 10);
        goodsMap.put("gtype", 1);
        goodsMap.put("gpntList", goodsPngList);
        goodsMap.put("gprice", BigDecimal.valueOf(10999.99));
        return goodsMap;
    }
}
